import {ref} from "vue";
import {getUserList} from "@/api/system/user";
import {searchForm} from "@/views/system/user/hooks/useSearch";
import {Page} from "@/utils/request";
import {Role} from "@/views/system/role/hooks/useTable";
import {Dept} from "@/views/system/dept/hooks/useTable";
export interface User {
    id: number;
    username: string;
    nickname: string;
    phone: string;
    avatar: string;
    roles: Role[];
    dept: Dept;
    createTime: string;
    updateTime: string;
}
const tableData = ref<User[]>()
const total =ref(0)
const tableLoading = ref(false)
export default function useTable() {
    function getUserDataList(){
        tableLoading.value = true
        getUserList(searchForm).then(res=>{
            const page = (res.data as Page<User>)
            tableData.value = page.list
            total.value = page.total
            tableLoading.value = false
        })
    }
    function handleCurrentPageChange(val: number) {
        searchForm.page = val
        getUserDataList()
    }
    function handlePageSizeChange(val: number) {
        searchForm.pageSize = val
        getUserDataList()
    }
    return {
        tableData,
        total,
        getUserDataList,
        tableLoading,
        handleCurrentPageChange,
        handlePageSizeChange
    }
}
